<!doctype html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>NodeCMS-添加用户</title>
    <link rel="stylesheet" href="/css/layui/css/layui.css">
    <link rel="stylesheet" href="/css/admin/reset.css">
    <link rel="stylesheet" href="/css/admin/admin.css">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <!-- 公共头部 -->
    <%- include('../common/header') %>
    <!-- 公共头部 -->
    <!-- 导航条 -->
    <%- include('../common/nav') %>
    <!-- 导航条 -->
    <div class="layui-body">
        <div class="container">
            <div class="layui-breadcrumb">
                <a href="/">首页</a>
                <a href="javascript:;">添加用户</a>
            </div>
            <div class="layui-form" lay-filter="item-info">
                <div class="layui-form-item">
                    <label class="layui-form-label">用户名</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" lay-verify="username" id="username" autocomplete="off" placeholder="请输入用户名" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="passwd" lay-verify="passwd" id="passwd" autocomplete="off" placeholder="请输入密码" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">身份设置</label>
                    <div class="layui-input-block">
                        <input type="radio" name="usertype" value="1" title="超级管理员">
                        <input type="radio" name="usertype" value="2" title="管理员" checked>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">资讯权限</label>
                    <div class="layui-input-block">
                        <input type="checkbox" value="1" name="newsAuthority" lay-skin="switch">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input type="button" id="submitBtn" class="layui-btn" value="提交">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<%- include('../common/importJs') %>
<script>
    layui.use(['element', 'form'], function(){
        var element = layui.element;
        var form = layui.form;
        $('#submitBtn').on('click', function(){
            var id = $(this).attr('data-id');
            var name = $(this).attr('data-name');
            var data = form.val('item-info');
            $.ajax({
                url: '/cms/addUser',
                type: 'post',
                data: {
                    username: data.username,
                    passwd: data.passwd,
                    usertype: data.usertype,
                    newsAuthority: data.newsAuthority
                },
                success: function(d){
                    if(d.code == 200){
                        window.location.href = '/admin/userList';
                    }
                }
            })
        })
    });
</script>
</body>
</html>